package com.work.music.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.work.music.common.HttpRequestParamter;
import com.work.music.common.ResponseJson;
import com.work.music.dao.*;
import com.work.music.entity.*;
import com.work.music.exception.AjaxOperationFailException;
import com.work.music.utils.FanyiV3Demo;
import com.work.music.utils.HttpUtil;
import com.work.music.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * Created by xs on 2019/4/14.
 */
@Service
@Transactional
public class MusicService extends BaseService {
    @Autowired
    private MusicAlbumMapper musicAlbumMapper;   //专辑
    @Autowired
    private MusicLyricsMapper musicLyricsMapper;  //歌词
    @Autowired
    private MusicSongsterMapper musicSongsterMapper;  //歌手
    @Autowired
    private MusicManagerMapper musicManagerMapper;  //歌曲管理
    @Autowired
    private MusicCollectPraiseMapper musicCollectPraiseMapper;   //点赞收藏
    @Autowired
    private CommentMapper commentMapper;   //评论
    @Autowired
    private WordMapper wordMapper;  //单词信息表
    @Autowired
    private FeedbackMapper feedbackMapper;  //意见反馈
    @Autowired
    private ImageMapper imageMapper;  //图片
    @Autowired
    private LyricsErrorMapper lyricsErrorMapper; //歌曲纠错
    @Autowired
    private ReportMapper reportMapper;  //举报
    @Autowired
    private WordInfoMapper wordInfoMapper;  //单词详情w
    @Autowired
    private MusicUserMapper musicUserMapper;
    @Autowired
    private IntegralTypeMapper integralTypeMapper;
    @Autowired
    private IntegralLogMapper integralLogMapper;
    @Autowired
    private IntegralMapper integralMapper;
    @Autowired
    private UserWordMapper userWordMapper;


    /**
     * 添加歌手
     *
     * @return
     */
    public ResponseJson addSongster() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String name = HttpRequestParamter.getString("name"); //歌手名称
        String headimg = HttpRequestParamter.getString("headimg");  //歌手头像
        String synopsis = HttpRequestParamter.getString("synopsis");  //简介

        if (StringUtil.isEmpty(name)) {
            throw new AjaxOperationFailException("请输入歌手姓名");
        }

        if (StringUtil.isNull(headimg)) {
            throw new AjaxOperationFailException("请选择歌手头像");
        }

        MusicSongster musicSongster = new MusicSongster();
        musicSongster.setHeadimg(headimg.replace(StringUtil.IMGURL, ""));
        musicSongster.setName(name);
        musicSongster.setStatus(0);
        musicSongster.setSynopsis(StringUtil.isEmpty(synopsis) ? "" : synopsis);
        musicSongster.setUid(uid);
        musicSongster.setAddtime(new Date());
        musicSongster.setAddip(HttpUtil.getClientIp());
        int tag = musicSongsterMapper.insert(musicSongster);
        if (tag <= 0) {
            throw new AjaxOperationFailException("新增失败");
        }

        return new ResponseJson();
    }

    /**
     * 获取歌手列表
     * 将歌手列表过滤去掉，默认展示所有已通过审核的歌手列表
     * 添加分页功能
     * 2020.05.04 LZH
     * @return
     */
    public ResponseJson getSongsterList() {
        // long uid = HttpRequestParamter.getUid();
        // int status = HttpRequestParamter.getInt("status", -1);
//        String msg = "";
//        if (status != -1) {
//            msg = " and status=" + status;
//        }

        // 当前第几页
        int pageNum = HttpRequestParamter.getInt("pageNum");
        // 每页多少条
        int pageSize = HttpRequestParamter.getInt("pageSize");

        PageHelper.startPage(pageNum,pageSize);
        PageInfo<MusicSongster> pageInfo = new PageInfo<>(musicSongsterMapper.selectListByUid());

        // List<MusicSongster> list = musicSongsterMapper.selectListByUid();  // uid, msg
        if (StringUtil.isListNull(pageInfo.getList())) {
            pageInfo = new PageInfo<>();
        } else {
            for (MusicSongster musicSongster : pageInfo.getList()) {
                musicSongster.setHeadimg(StringUtil.getImg(musicSongster.getHeadimg()));
            }
        }
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(pageInfo.getList());
        return responseJson;
    }

    /**
     * 添加专辑
     *
     * @return
     * @throws AjaxOperationFailException
     */
    public ResponseJson addAlbum() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String name = HttpRequestParamter.getString("name");   //专辑名称
        long songsterId = HttpRequestParamter.getLong("songsterId", -1);  //歌手id
        String cover = HttpRequestParamter.getString("cover");  //封面
        String synopsis = HttpRequestParamter.getString("synopsis");  //简介
        if (StringUtil.isEmpty(name)) {
            throw new AjaxOperationFailException("请输入专辑名称");
        }
        if (StringUtil.isNull(cover)) {
            throw new AjaxOperationFailException("请选择封面");
        }
        if (songsterId == -1) {
            throw new AjaxOperationFailException("请选择歌手");
        }

        MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(songsterId);
        if (musicSongster == null) {
            throw new AjaxOperationFailException("该歌手不存在");
        }
        if (musicSongster.getStatus() != 1) {
            throw new AjaxOperationFailException("该歌手审核中或审核未通过");
        }
        if (musicSongster.getUid() != uid) {
            throw new AjaxOperationFailException("该歌手信息与您无关");
        }

        MusicAlbum musicAlbum = new MusicAlbum();
        musicAlbum.setAddip(HttpUtil.getClientIp());
        musicAlbum.setAddtime(new Date());
        musicAlbum.setCover(cover.replace(StringUtil.IMGURL, ""));
        musicAlbum.setName(name);
        musicAlbum.setSongsterId(songsterId);
        musicAlbum.setStatus(0);
        musicAlbum.setUid(uid);
        musicAlbum.setSynopsis(StringUtil.isEmpty(synopsis) ? "" : synopsis);
        int tag = musicAlbumMapper.insert(musicAlbum);
        if (tag <= 0) {
            throw new AjaxOperationFailException("新增失败");
        }
        return new ResponseJson();
    }

    /**
     * 获取专辑列表
     * 更改原先uid错误传参，增加歌手id-->songster_id,去掉状态判断，改为status = 1
     * 添加分页功能
     * 2020.05.04 LZH
     * @return
     */
    public ResponseJson getAlbumList() {
        long songster_id = HttpRequestParamter.getLong("songster_id");
//        int status = HttpRequestParamter.getInt("status", -1);
//        String msg = "";
//        if (status != -1) {
//            msg = " and status = " + status;
//        }
        // 当前第几页
        int pageNum = HttpRequestParamter.getInt("pageNum");
        // 每页多少条
        int pageSize = HttpRequestParamter.getInt("pageSize");

        PageHelper.startPage(pageNum,pageSize);
        PageInfo<MusicAlbum> pageInfo = new PageInfo<>(musicAlbumMapper.getAlbumListByUid(songster_id));

        // List<MusicAlbum> list = musicAlbumMapper.getAlbumListByUid(songster_id);
        if (pageInfo.getList() == null || pageInfo.getList().size() <= 0) {
            pageInfo = new PageInfo<>();
        } else {
            for (MusicAlbum musicAlbum : pageInfo.getList()) {
                musicAlbum.setCover(StringUtil.getImg(musicAlbum.getCover()));
            }
        }
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(pageInfo.getList());
        return responseJson;
    }

    /**
     * 添加歌词
     *
     * @return
     */
    public ResponseJson addLyrics() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long songsterId = HttpRequestParamter.getLong("songsterId", -1);  //歌手id
        long albumId = HttpRequestParamter.getLong("albumId", -1);  //专辑id
        String cover = HttpRequestParamter.getString("cover");  //封面
        String synopsis = HttpRequestParamter.getString("synopsis");  //歌词
        String translate = HttpRequestParamter.getString("translate");  //翻译
        int type = HttpRequestParamter.getInt("type", 0);
        String name = HttpRequestParamter.getString("name");

        if (songsterId == -1) {
            throw new AjaxOperationFailException("请选择歌手");
        }
        if (StringUtil.isEmpty(name)) {
            throw new AjaxOperationFailException("请输入歌曲名");
        }
        if (StringUtil.isEmpty(synopsis)) {
            throw new AjaxOperationFailException("请输入歌词");
        }
        if (StringUtil.isNull(translate)) {
            translate = "";
        }
        MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(songsterId);
        if (musicSongster == null) {
            throw new AjaxOperationFailException("该歌手信息不存在");
        }
        if (musicSongster.getStatus() != 1) {
            throw new AjaxOperationFailException("该歌手审核中或审核未通过");
        }
        if (musicSongster.getUid() != uid) {
            throw new AjaxOperationFailException("该歌手信息与您无关");
        }
        if (type == 0) {
            if (albumId == -1) {
                throw new AjaxOperationFailException("请选择专辑");
            }
            MusicAlbum musicAlbum = musicAlbumMapper.selectByPrimaryKey(albumId);
            if (musicAlbum == null) {
                throw new AjaxOperationFailException("该专辑信息不存在");
            }
            if (musicAlbum.getStatus() != 1) {
                throw new AjaxOperationFailException("该专辑审核中或审核未通过");
            }
            if (musicAlbum.getUid() != uid) {
                throw new AjaxOperationFailException("该专辑与您无关");
            }
        } else {
            if (StringUtil.isNull(cover)) {
                throw new AjaxOperationFailException("请选择封面");
            }
        }
        MusicLyrics musicLyrics = new MusicLyrics();
        musicLyrics.setUid(uid);
        musicLyrics.setName(name);
        musicLyrics.setSongsterId(songsterId);
        musicLyrics.setType(type == 0 ? 0 : 1);
        if (type == 0) {
            musicLyrics.setAlbumId(albumId);
        } else {
            musicLyrics.setCover(cover.replace(StringUtil.IMGURL, ""));
        }
        musicLyrics.setSynopsis(synopsis);
        musicLyrics.setStatus(0);
        musicLyrics.setAddip(HttpUtil.getClientIp());
        musicLyrics.setAddtime(new Date());
        musicLyrics.setTranslate(translate);
        int tag = musicLyricsMapper.insert(musicLyrics);
        if (tag <= 0) {
            throw new AjaxOperationFailException("添加失败");
        }
        return new ResponseJson();
    }

    /**
     * 编辑歌手信息
     *
     * @return
     */
    public ResponseJson editSongster() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long songsterId = HttpRequestParamter.getLong("songsterId", -1);
        String name = HttpRequestParamter.getString("name"); //歌手名称
        String headimg = HttpRequestParamter.getString("headimg");  //歌手头像
        String synopsis = HttpRequestParamter.getString("synopsis");  //简介

        if (songsterId == -1) {
            throw new AjaxOperationFailException("请选择需要编辑的歌手");
        }
        MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(songsterId);
        if (musicSongster == null) {
            throw new AjaxOperationFailException("该歌手信息不存在");
        }

        if (musicSongster.getUid() != uid) {
            throw new AjaxOperationFailException("该专辑信息与您无关");
        }

        if (!StringUtil.isEmpty(name)) {
            musicSongster.setName(name);
        }
        if (!StringUtil.isNull(headimg)) {
            musicSongster.setHeadimg(headimg.replace(StringUtil.IMGURL, ""));
        }
        if (!StringUtil.isEmpty(synopsis)) {
            musicSongster.setSynopsis(synopsis);
        }

        musicSongster.setStatus(0);
        musicSongster.setReason("");
        int tag = musicSongsterMapper.updateByPrimaryKey(musicSongster);
        if (tag <= 0) {
            throw new AjaxOperationFailException("歌手信息修改失败");
        }

        return new ResponseJson();
    }

    /**
     * 编辑专辑信息
     *
     * @return
     */
    public ResponseJson editAlbum() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long albumId = HttpRequestParamter.getLong("albumId", -1);
        String name = HttpRequestParamter.getString("name");   //专辑名称
        long songsterId = HttpRequestParamter.getLong("songsterId", -1);  //歌手id
        String cover = HttpRequestParamter.getString("cover");  //封面
        String synopsis = HttpRequestParamter.getString("synopsis");  //简介

        if (albumId == -1) {
            throw new AjaxOperationFailException("请选择需要编辑的专辑");
        }

        MusicAlbum musicAlbum = musicAlbumMapper.selectByPrimaryKey(albumId);

        if (musicAlbum == null) {
            throw new AjaxOperationFailException("该专辑信息不存在");
        }

        if (musicAlbum.getUid() != uid) {
            throw new AjaxOperationFailException("该专辑信息与您无关");
        }

        if (!StringUtil.isEmpty(name)) {
            musicAlbum.setName(name);
        }

        if (songsterId != -1) {
            MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(songsterId);
            if (musicSongster == null) {
                throw new AjaxOperationFailException("该歌手不存在");
            }
            if (musicSongster.getStatus() != 1) {
                throw new AjaxOperationFailException("该歌手审核中或未通过审核");
            }
            if (musicSongster.getUid() != uid) {
                throw new AjaxOperationFailException("该歌手信息与您无关");
            }
            musicAlbum.setSongsterId(songsterId);
        }

        if (!StringUtil.isNull(cover)) {
            musicAlbum.setCover(cover.replace(StringUtil.IMGURL, ""));
        }

        if (!StringUtil.isEmpty(synopsis)) {
            musicAlbum.setSynopsis(synopsis);
        }

        musicAlbum.setStatus(0);
        musicAlbum.setReason("");
        int tag = musicAlbumMapper.updateByPrimaryKey(musicAlbum);
        if (tag <= 0) {
            throw new AjaxOperationFailException("编辑失败");
        }
        return new ResponseJson();
    }

    /**
     * 编辑歌词
     *
     * @return
     */
    public ResponseJson editLyrics() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long lyricsId = HttpRequestParamter.getLong("lyricsId", -1);
        long songsterId = HttpRequestParamter.getLong("songsterId", -1);  //歌手id
        long albumId = HttpRequestParamter.getLong("albumId", -1);  //专辑id
        String cover = HttpRequestParamter.getString("cover");  //封面
        String synopsis = HttpRequestParamter.getString("synopsis");  //歌词
        String translate = HttpRequestParamter.getString("translate");  //翻译
        String name = HttpRequestParamter.getString("name");

        if (lyricsId == -1) {
            throw new AjaxOperationFailException("请选择需要编辑的歌词");
        }

        MusicLyrics musicLyrics = musicLyricsMapper.selectByPrimaryKey(lyricsId);
        if (musicLyrics == null) {
            throw new AjaxOperationFailException("该歌词信息不存在");
        }

        if (musicLyrics.getUid() != uid) {
            throw new AjaxOperationFailException("该歌词信息与您无关");
        }

        if (!StringUtil.isEmpty(name)) {
            musicLyrics.setName(name);
        }
        if (!StringUtil.isEmpty(synopsis)) {
            musicLyrics.setSynopsis(synopsis);
        }
        if (!StringUtil.isNull(translate)) {
            musicLyrics.setTranslate(translate);
        }

        if (songsterId != -1) {
            MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(songsterId);
            if (musicSongster == null) {
                throw new AjaxOperationFailException("该歌手信息不存在");
            }
            if (musicSongster.getStatus() != 1) {
                throw new AjaxOperationFailException("该歌手审核中或审核未通过");
            }
            if (musicSongster.getUid() != uid) {
                throw new AjaxOperationFailException("该歌手信息与您无关");
            }
            musicLyrics.setSongsterId(songsterId);
        }

        if (albumId != -1) {
            MusicAlbum musicAlbum = musicAlbumMapper.selectByPrimaryKey(albumId);
            if (musicAlbum == null) {
                throw new AjaxOperationFailException("该专辑信息不存在");
            }
            if (musicAlbum.getStatus() != 1) {
                throw new AjaxOperationFailException("该专辑审核中或审核未通过");
            }
            if (musicAlbum.getUid() != uid) {
                throw new AjaxOperationFailException("该专辑与您无关");
            }
            musicLyrics.setAlbumId(albumId);
        }

        if (!StringUtil.isNull(cover)) {
            musicLyrics.setCover(cover.replace(StringUtil.IMGURL, ""));
        }

        musicLyrics.setStatus(0);
        musicLyrics.setReason("");
        int tag = musicLyricsMapper.updateByPrimaryKey(musicLyrics);
        if (tag <= 0) {
            throw new AjaxOperationFailException("编辑失败");
        }
        return new ResponseJson();
    }

    public ResponseJson getSearchInfo() {
        int page = HttpRequestParamter.getInt("page", 1);
        int count = HttpRequestParamter.getInt("count", 10);
        String search = HttpRequestParamter.getString("search");
        if (StringUtil.isNull(search)) {
            return new ResponseJson();
        }
        long uid = HttpRequestParamter.getUid();
        String msg = "where 1=1";
        if (uid == 0) {
            msg += "and l.status=1 ";
        } else {
            MusicUser musicUser = musicUserMapper.selectByPrimaryKey(uid);
            if (musicUser == null || musicUser.getState() != 1) {
                msg += "and l.status=1 ";
            } else {
                msg += "and l.status!=2";
            }
        }
        msg += " and l.name like '%" + search + "%'";
        List<Map<String, Object>> list = musicLyricsMapper.getSearchInfo(msg, (page - 1) * count, count);
        if (StringUtil.isListNull(list)) {
            return new ResponseJson();
        }
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        Map<String, Object> resultMap;
        for (Map<String, Object> map : list) {
            resultMap = new HashMap<String, Object>();
            resultMap.put("id", map.get("id"));
            resultMap.put("musicType", map.get("musicType"));
            resultMap.put("type", map.get("type"));
            if ("0".equals(map.get("musicType") + "")) {
                resultMap.put("lname", "");
                resultMap.put("aname", "");
                resultMap.put("sname", map.get("lname") + "");
                resultMap.put("cover", StringUtil.getImg(map.get("lcover") + ""));
            } else if ("1".equals(map.get("musicType") + "")) {
                resultMap.put("lname", "");
                resultMap.put("aname", map.get("lname") + "");
                resultMap.put("sname", map.get("sname"));
                resultMap.put("cover", StringUtil.getImg(map.get("lcover") + ""));
            } else {
                resultMap.put("lname", map.get("lname"));
                resultMap.put("aname", map.get("aname"));
                resultMap.put("sname", map.get("sname"));
                if ("0".equals(map.get("type") + "")) {
                    resultMap.put("cover", StringUtil.getImg(map.get("acover") + ""));
                } else {
                    resultMap.put("cover", StringUtil.getImg(map.get("lcover") + ""));
                }
            }
            result.add(resultMap);
        }
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(result);
        return responseJson;
    }

    /**
     * 获取首页信息
     *
     * @param state
     * @return
     */
    public ResponseJson getHomePage(int state) throws AjaxOperationFailException {
        int page = HttpRequestParamter.getInt("page", 1);
        int count = HttpRequestParamter.getInt("count", 20);
        long songsterid = HttpRequestParamter.getLong("songsterId", -1);  //歌手id
        long albumId = HttpRequestParamter.getLong("albumId", -1);  //歌手id
        int type = HttpRequestParamter.getInt("type", -1);  //歌曲类型
        long uid = HttpRequestParamter.getUid();


        StringBuffer stringBuffer = new StringBuffer("where 1=1");
        if (uid == 0) {
            stringBuffer.append(" and status=1");
        } else {
            MusicUser musicUser = musicUserMapper.selectByPrimaryKey(uid);
            if (musicUser == null || musicUser.getState() != 1) {
                stringBuffer.append(" and status=1");
            } else {
                stringBuffer.append(" and status!=2");
            }
        }
        if (state == 1) {
            if (songsterid == -1) {
                throw new AjaxOperationFailException("缺少参数：歌手id");
            }
            if (type == -1) {
                throw new AjaxOperationFailException("缺少参数：歌曲类型");
            }
        } else if (state == 2) {
            if (albumId == -1) {
                throw new AjaxOperationFailException("缺少参数：专辑id");
            }
        } else if (state == 3) {
            stringBuffer.append(" and id in (select typeid from music_collect_praise where uid=").append(uid).append(" and type=2 and peration=1 and status=1)");
        }
        if (songsterid != -1 && type != -1) {
            stringBuffer.append(" and songster_id=").append(songsterid).append(" and type=").append(type);
        }
        if (albumId != -1) {
            stringBuffer.append(" and album_id=").append(albumId);
        }

        List<MusicLyricsManager> list = musicManagerMapper.selectLyricsList(stringBuffer.toString(), (page - 1) * count, count);
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        if (list != null && list.size() > 0) {
            Map<String, Object> resultMap;
            for (MusicLyricsManager musicLyricsManager : list) {
                resultMap = new HashMap<String, Object>();
                resultMap.put("id", musicLyricsManager.getId());
                resultMap.put("type", musicLyricsManager.getType());
                resultMap.put("lname", musicLyricsManager.getName());
                resultMap.put("sname", musicLyricsManager.getMusicSongster().getName());
                getLyricsCover(resultMap, musicLyricsManager);
                resultList.add(resultMap);
            }
        }
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(resultList);
        return responseJson;
    }

    public ResponseJson musicPraiseCollect(int peration) throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        int type = HttpRequestParamter.getInt("type", -1);  //0:歌手 1：专辑  2：歌曲  3：单词
        long typeid = HttpRequestParamter.getLong("typeid", -1);  //类型id
        int status = HttpRequestParamter.getInt("status", -1); //状态（1：收藏、关注或点赞  2：取消收藏、取消关注或取消点赞）

        String msg = "";
        if (peration == 0) {
            msg = "点赞";
        } else if (peration == 1) {
            msg = "收藏";
        } else {
            msg = "关注";
        }

        if (type == -1) {
            throw new AjaxOperationFailException("请选择" + msg + "类型");
        }
        if (typeid == -1) {
            throw new AjaxOperationFailException("请选择需要" + msg + "相关信息");
        }
        if (status == -1) {
            throw new AjaxOperationFailException("请选择" + msg + "的状态");
        }


        MusicCollectPraise musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, type, typeid, peration);
        int tag;
        if (musicCollectPraise == null) {
            musicCollectPraise = new MusicCollectPraise();
            musicCollectPraise.setAddip(HttpUtil.getClientIp());
            musicCollectPraise.setAddtime(new Date());
            musicCollectPraise.setPeration(peration);
            musicCollectPraise.setStatus(status == 1 ? 1 : 2);
            musicCollectPraise.setType(type);
            musicCollectPraise.setTypeid(typeid);
            musicCollectPraise.setUid(uid);
            tag = musicCollectPraiseMapper.insert(musicCollectPraise);
        } else {
            if (status == musicCollectPraise.getStatus()) {
                return new ResponseJson();
            } else {
                musicCollectPraise.setAddip(HttpUtil.getClientIp());
                musicCollectPraise.setAddtime(new Date());
                musicCollectPraise.setStatus(status == 1 ? 1 : 2);
                tag = musicCollectPraiseMapper.updateByPrimaryKey(musicCollectPraise);
            }
        }
        if (tag <= 0) {
            throw new AjaxOperationFailException("操作失败");
        }
        return new ResponseJson();
    }

    /**
     * 根据id获取歌曲详情
     *
     * @return
     */
    public ResponseJson getLyricsById() throws AjaxOperationFailException {
        long id = HttpRequestParamter.getLong("id", -1);
        long uid = HttpRequestParamter.getUid();
        if (id == -1) {
            throw new AjaxOperationFailException("缺失参数：id");
        }
        MusicLyricsManager musicLyricsManager = musicManagerMapper.getLyricsById(id);
        if (musicLyricsManager == null) {
            throw new AjaxOperationFailException("未找到相关信息");
        }

        ResponseJson responseJson = new ResponseJson();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", musicLyricsManager.getId());
        map.put("type", musicLyricsManager.getType());
        map.put("lname", musicLyricsManager.getName());
        map.put("sname", musicLyricsManager.getMusicSongster().getName());
        map.put("sid", musicLyricsManager.getMusicSongster().getId());
        map.put("synopsis", musicLyricsManager.getSynopsis()); //歌词
        map.put("translate", musicLyricsManager.getTranslate()); //翻译
        map.put("nickName", musicLyricsManager.getNickName()); //昵称

        //获取歌曲收藏总条数
        int count = musicCollectPraiseMapper.selectCountByTypeId(2, id, 1);
        map.put("collectCount", count);
        //判断是否收藏、点赞及关注歌手
        if (uid == 0) {
            map.put("isCollect", 0);
            map.put("isPraise", 0);
            map.put("isConcern", 0);
            map.put("isMyself", 0);
        } else {
            // 操作类型（0：点赞  1：收藏 2：关注）
            //是否点赞
            MusicCollectPraise musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, 2, id, 0);
            if (musicCollectPraise == null || musicCollectPraise.getStatus() != 1) {
                map.put("isPraise", 0);
            } else {
                map.put("isPraise", 1);
            }
            //是否收藏
            musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, 2, id, 1);
            if (musicCollectPraise == null || musicCollectPraise.getStatus() != 1) {
                map.put("isCollect", 0);
            } else {
                map.put("isCollect", 1);
            }
            //是否关注
            musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, 0, musicLyricsManager.getMusicSongster().getId(), 2);
            if (musicCollectPraise == null || musicCollectPraise.getStatus() != 1) {
                map.put("isConcern", 0);
            } else {
                map.put("isConcern", 1);
            }
            if (uid == musicLyricsManager.getMusicUser().getId()) {
                map.put("isMyself", 1);
            } else {
                map.put("isMyself", 0);
            }
        }

        getLyricsCover(map, musicLyricsManager);

        responseJson.setObj(map);
        return responseJson;
    }

    /**
     * 获取我的收藏
     *
     * @return
     */
    public ResponseJson getCollect() {
        int page = HttpRequestParamter.getInt("page", 1);
        int count = HttpRequestParamter.getInt("count", 20);
        long uid = HttpRequestParamter.getUid();
        //获取我的收藏
        List<MusicCollectPraise> collect = musicCollectPraiseMapper.getAllByUid(uid, (page - 1) * count, count);
        if (collect == null) {
            return new ResponseJson();
        }
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> map;
        for (MusicCollectPraise musicCollectPraise : collect) {
            map = new HashMap<String, Object>();
            MusicLyricsManager musicLyricsManager = musicManagerMapper.getLyricsById(musicCollectPraise.getTypeid());
            if (musicLyricsManager == null) {
                continue;
            }
            map.put("id", musicLyricsManager.getId());
            map.put("type", musicLyricsManager.getType());
            map.put("lname", musicLyricsManager.getName());
            map.put("sname", musicLyricsManager.getMusicSongster().getName());
            getLyricsCover(map, musicLyricsManager);
            list.add(map);
        }
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(list);
        return responseJson;
    }

    private void getLyricsCover(Map<String, Object> map, MusicLyricsManager musicLyricsManager) {
        if (musicLyricsManager.getType() == 0) {
            MusicAlbum musicAlbum = musicLyricsManager.getMusicAlbum();
            map.put("aname", musicAlbum.getName());
            map.put("cover", StringUtil.getImg(musicAlbum.getCover()));
        } else {
            map.put("cover", StringUtil.getImg(musicLyricsManager.getCover()));
            map.put("aname", "");
        }
    }

    public ResponseJson addComment() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long typeid = HttpRequestParamter.getLong("typeid", -1);
        long commentId = HttpRequestParamter.getLong("commentId", 0);   //评论id
        int type = HttpRequestParamter.getInt("type", 0);  //评论类型（0：文字  1：图片  2：语音  3:视频）
        String content = HttpRequestParamter.getString("content");
        if (typeid == -1) {
            throw new AjaxOperationFailException("请选择需要评价的歌曲");
        }
        if (StringUtil.isEmpty(content)) {
            throw new AjaxOperationFailException("请输入评价内容");
        }
        if (type != 0 && type != 1 && type != 2 && type != 3) {
            type = 0;
        }
        Comment comment = new Comment();
        comment.setUid(uid);
        comment.setUpid(commentId);
        comment.setType(type);
        comment.setTypeid(typeid);
        comment.setContent(content);
        comment.setAddtime(new Date());
        comment.setAddip(HttpUtil.getClientIp());
        int tag = commentMapper.insert(comment);
        if (tag <= 0) {
            throw new AjaxOperationFailException("评论失败");
        }

        ResponseJson responseJson = new ResponseJson();
        if (commentId == 0) {
            responseJson.setObj(comment.getId());
        } else {
            responseJson.setObj(commentId);
        }
        return responseJson;
    }

    /**
     * 获取歌手详情
     *
     * @return
     * @throws AjaxOperationFailException
     */
    public ResponseJson getSongsterInfo() throws AjaxOperationFailException {
        long id = HttpRequestParamter.getLong("id", -1);
        long uid = HttpRequestParamter.getUid();
        if (id == -1) {
            throw new AjaxOperationFailException("缺少参数：歌手id");
        }
        MusicSongster musicSongster = musicSongsterMapper.selectByPrimaryKey(id);
        if (musicSongster == null) {
            throw new AjaxOperationFailException("该歌手信息不存在");
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("name", musicSongster.getName());
        map.put("headimg", StringUtil.getImg(musicSongster.getHeadimg()));
        map.put("synopsis", musicSongster.getSynopsis());
        if (uid == 0) {
            map.put("isConcern", 0);
            map.put("isMyself", 0);
        } else {
            if (uid == musicSongster.getUid()) {
                map.put("isMyself", 1);
            } else {
                map.put("isMyself", 0);
            }
            //是否关注
            MusicCollectPraise musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, 0, musicSongster.getUid(), 2);
            if (musicCollectPraise == null || musicCollectPraise.getStatus() != 1) {
                map.put("isConcern", 0);
            } else {
                map.put("isConcern", 1);
            }
        }
        //获取该歌手的关注数
        int count = musicCollectPraiseMapper.selectCountByTypeId(0, id, 2);
        map.put("concernCount", count);
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(map);
        return responseJson;
    }

    /**
     * 获取专辑详情
     *
     * @return
     */
    public ResponseJson getAlbumInfo() throws AjaxOperationFailException {
        long id = HttpRequestParamter.getLong("id", -1);
        long uid = HttpRequestParamter.getUid();
        if (id == -1) {
            throw new AjaxOperationFailException("缺少参数：歌手id");
        }
        MusicAlbumManager musicAlbumManager = musicManagerMapper.getAlbumById(id);
        if (musicAlbumManager == null) {
            throw new AjaxOperationFailException("未找到相关信息");
        }
        long sid = musicAlbumManager.getMusicSongster().getId();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("sid", sid);
        map.put("aname", musicAlbumManager.getName());
        map.put("sname", musicAlbumManager.getMusicSongster().getName());
        map.put("headimg", StringUtil.getImg(musicAlbumManager.getMusicSongster().getHeadimg()));
        map.put("cover", StringUtil.getImg(musicAlbumManager.getCover()));
        map.put("synopsis", musicAlbumManager.getSynopsis());

        //获取是否关注
        if (uid == 0) {
            map.put("isConcern", 0);
            map.put("isMyself", 0);
        } else {
            if (uid == musicAlbumManager.getMusicUser().getId()) {
                map.put("isMyself", 1);
            } else {
                map.put("isMyself", 0);
            }
            //是否关注
            MusicCollectPraise musicCollectPraise = musicCollectPraiseMapper.selectByPrimaryKey(uid, 0, musicAlbumManager.getMusicSongster().getId(), 2);
            if (musicCollectPraise == null || musicCollectPraise.getStatus() != 1) {
                map.put("isConcern", 0);
            } else {
                map.put("isConcern", 1);
            }
        }
        //获取关注总数
        int count = musicCollectPraiseMapper.selectCountByTypeId(0, sid, 2);
        map.put("concernCount", count);
        ResponseJson responseJson = new ResponseJson();
        responseJson.setObj(map);
        return responseJson;
    }

    public ResponseJson getWord() {
        long uid = HttpRequestParamter.getUid();
        int page = HttpRequestParamter.getInt("page", 1);
        int count = HttpRequestParamter.getInt("count", 20);
        List<Map<String, Object>> list = wordMapper.selectByUid(uid, (page - 1) * 10, count);
//        List<Map<String, Object>> list = wordInfoMapper.selectByUid(uid, (page - 1) * 10, count);
        ResponseJson responseJson = new ResponseJson();
        responseJson.setList(list);
        return responseJson;
    }

    public ResponseJson getWordByName() throws AjaxOperationFailException {
        String name = HttpRequestParamter.getString("name");
        if (StringUtil.isEmpty(name)) {
            throw new AjaxOperationFailException("缺少参数：单词名");
        }
        Word word = wordMapper.selectByName(name);
        if(word == null) {
            throw new AjaxOperationFailException("未找到相关信息");
        }
        return new ResponseJson(word, null);
    }

    /**
     * 添加意见反馈
     * @return
     */
    public ResponseJson addFeedback() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String content = HttpRequestParamter.getString("content");
        String imgList = HttpRequestParamter.getString("imgList");
        if(StringUtil.isNull(content)) {
            throw new AjaxOperationFailException("请输入反馈意见");
        }
        String feedbackId = StringUtil.getUUid();
        Feedback feedback = new Feedback();
        feedback.setId(feedbackId);
        feedback.setAddip(HttpUtil.getClientIp());
        feedback.setAddtime(new Date());
        feedback.setContent(content);
        feedback.setStatus(0);
        feedback.setUid(uid);
        int tag = feedbackMapper.insert(feedback);
        if(tag <= 0) {
            throw new AjaxOperationFailException("操作失败");
        }
        addImage(imgList, feedbackId, imageMapper, 1);
        return new ResponseJson();
    }

    private void addImage(String imgList, String feedbackId, ImageMapper imageMapper, int type) throws AjaxOperationFailException {
        int tag;
        String imgs[] = imgList.replace("，", ",").split(",");
        Image image;
        for (String img: imgs) {
            image = new Image();
            image.setId(StringUtil.getUUid());
            image.setType(type);
            image.setTypeId(feedbackId);
            image.setImgurl(img.replace(StringUtil.IMGURL, ""));
            image.setAddtime(new Date());
            image.setAddip(HttpUtil.getClientIp());
            tag = imageMapper.insert(image);
            if(tag <= 0) {
                throw new AjaxOperationFailException("操作失败");
            }
        }
    }

    /**
     * 歌曲纠错
     * @return
     */
    public ResponseJson addLyricsError() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String content = HttpRequestParamter.getString("content");
        String imgList = HttpRequestParamter.getString("imgList");
        long lyricsId = HttpRequestParamter.getLong("lyricsId", -1);
        String  type = HttpRequestParamter.getString("type");
        if (StringUtil.isNull(content)) {
            throw new AjaxOperationFailException("请输入纠错内容");
        }
        if(lyricsId == -1) {
            throw new AjaxOperationFailException("缺少参数：歌曲id");
        }
        if(StringUtil.isNull(type)) {
            throw new AjaxOperationFailException("请选择纠错类型");
        }
        String lyricsErrorId = StringUtil.getUUid();
        LyricsError lyricsError = new LyricsError();
        lyricsError.setId(lyricsErrorId);
        lyricsError.setUid(uid);
        lyricsError.setLyricsId(lyricsId);
        lyricsError.setContent(content);
        lyricsError.setType(type);
        lyricsError.setAddtime(new Date());
        lyricsError.setAddip(HttpUtil.getClientIp());
        lyricsError.setStatus(0);
        int tag = lyricsErrorMapper.insert(lyricsError);
        if(tag <= 0) {
            throw new AjaxOperationFailException("操作失败");
        }
        addImage(imgList, lyricsErrorId, imageMapper, 0);
        return new ResponseJson();
    }

    public ResponseJson getComment() throws AjaxOperationFailException {
        long typeid = HttpRequestParamter.getLong("typeid", -1);
        int page = HttpRequestParamter.getInt("page", 1);  //页码
        int count = HttpRequestParamter.getInt("count", 20); //每页显示条数
        long uid = HttpRequestParamter.getUid();
        if (typeid == -1) {
            throw new AjaxOperationFailException("缺少参数：类型id");
        }
        if (page <= 0) {
            page = 1;
        }

        List<MusicCommentManager> list = commentMapper.selectByTypeAndTypeId(typeid, (page - 1) * count, count);
        List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
        if (list != null) {
            Map<String, Object> resultMap;
            String phone;
            String nickname;
            int registerType;
            String email;
            String resultNickname;
            for (MusicCommentManager musicCommentManager: list) {
                resultMap = new HashMap<String, Object>();
                phone = musicCommentManager.getMusicUser().getPhone();
                nickname = musicCommentManager.getMusicUser().getNickName();
                email = musicCommentManager.getMusicUser().getNickName();
                registerType = musicCommentManager.getMusicUser().getRegisterType();
                if (registerType == 0) {
                    resultNickname = phone;
                } else if(registerType == 1) {
                    resultNickname = email;
                } else {
                    resultNickname = nickname;
                }
                resultMap.put("headimg", StringUtil.getImg(musicCommentManager.getMusicUser().getHeadimg()));
                resultMap.put("nickName", resultNickname);
                resultMap.put("addtime", musicCommentManager.getAddtime());
                resultMap.put("content", musicCommentManager.getContent());
                resultMap.put("commentid", musicCommentManager.getId());
                resultMap.put("commentUpId", musicCommentManager.getUpid());
                resultMap.put("type", musicCommentManager.getType());
                if (uid == 0) {
                    resultMap.put("ispraise", 0);
                    resultMap.put("ismyself", 0);
                } else {
                    if (uid == musicCommentManager.getMusicUser().getId()) {
                        resultMap.put("ismyself", 1);
                    } else {
                        resultMap.put("ismyself", 0);
                    }
                    int ispraise = musicCollectPraiseMapper.selectCountByTypeAndTypeIdAndUid(3, musicCommentManager.getId(), 0, uid);
                    if (ispraise > 0) {
                        resultMap.put("ispraise", 1);
                    } else {
                        resultMap.put("ispraise", 0);
                    }
                }
                int praisecount = musicCollectPraiseMapper.selectCountByTypeId(3, musicCommentManager.getId(), 0);
                resultMap.put("praisecount", praisecount);
                resultList.add(resultMap);
            }
        }
        return new ResponseJson(null, resultList);
    }

    /**
     * 删除评论
     * @return
     */
    public ResponseJson removeComment() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long commentid = HttpRequestParamter.getLong("commentid", 0);
        if (commentid == 0){
            throw new AjaxOperationFailException("请选择需要删除的评论");
        }
        Comment comment = commentMapper.selectByPrimaryKey(commentid);
        if (comment == null) {
            return new ResponseJson();
        }
        if (uid != comment.getUid()) {
            throw new AjaxOperationFailException("该评论与您无关");
        }
        commentMapper.deleteByPrimaryKey(commentid);
        return new ResponseJson();
    }

    /**
     * 举报
     * @return
     */
    public ResponseJson addReport() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        //类型（0：用户  1：歌手 2：歌曲 3：专辑  4：歌词  5：评论）
        int type = HttpRequestParamter.getInt("type", 0);
        long typeid = HttpRequestParamter.getLong("typeid", 0);
        String content = HttpRequestParamter.getString("content");
        if (type < 0 || (type != 0 && type != 1 && type != 2 && type != 3 && type != 4 && type != 5)) {
            throw new AjaxOperationFailException("不存在该举报类型");
        }
        if (typeid <= 0) {
            throw new AjaxOperationFailException("请选择需要举报的相关信息");
        }
        if (StringUtil.isNull(content)) {
            content = "";
        }
        Report report = new Report();
        report.setUid(uid);
        report.setType(type);
        report.setTypeid(typeid);
        report.setContent(content);
        report.setAddtime(new Date());
        report.setAddip(HttpUtil.getClientIp());
        reportMapper.insert(report);
        return new ResponseJson();
    }

    /**
     * 根据单词获取详情信息
     * @return
     */
    public ResponseJson getWordInfoByName() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String word = HttpRequestParamter.getString("word");
        if (StringUtil.isEmpty(word)) {
            throw new AjaxOperationFailException("请选择需要查询的单词信息");
        }
        WordInfo wordInfo = wordInfoMapper.selectByWordName(word);
        int iscollect = 0;
        if (wordInfo == null) {
            wordInfo = FanyiV3Demo.jsonToWordInfo(word);
            if (wordInfo == null) {
                throw new AjaxOperationFailException("获取失败");
            }
            wordInfoMapper.insert(wordInfo);
        } else {
            int count = musicCollectPraiseMapper.selectCountByTypeAndTypeIdAndUid(4, wordInfo.getId(), 1, uid);
            if (count > 0) {
                iscollect = 1;
            }
        }
        WordCollectInfo wordCollectInfo = new WordCollectInfo(wordInfo, iscollect);
        return new ResponseJson(wordCollectInfo, null);
    }

    /**
     * 根据单词获取单词详情
     * @return
     */
    public ResponseJson getWordIsHaveByTargetWord() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        String name = HttpRequestParamter.getString("targetWord");
        if (StringUtil.isNull(name)) {
            throw new AjaxOperationFailException("请选择需要查询的单词");
        }
        Word word = wordMapper.selectByName(name);
        if (word == null) {
            return new ResponseJson(0, "该单词不存在", null, null);
        } else {
            int count = musicCollectPraiseMapper
                    .selectCountByTypeAndTypeIdAndUid(4, word.getId(), 1, uid);
            WordCollect wordCollect;
            if (count > 0) {
                wordCollect = new WordCollect(word, 1);
            } else {
                wordCollect = new WordCollect(word, 0);
            }
            return new ResponseJson(wordCollect, null);
        }
    }

    /**
     * 添加单词
     *
     * @return
     */
    public ResponseJson addWord() throws AjaxOperationFailException {
        String targetWord = HttpRequestParamter.getString("targetWord");    //目标语言单词
        String phonetic = HttpRequestParamter.getString("phonetic");        //发音音标，除了英语，别的语言可能没有
        String chineseWord = HttpRequestParamter.getString("chineseWord");  //翻译后的中文单词
        String voiceFileUrl = HttpRequestParamter.getString("voiceFileUrl");//外语单词的发音音频文件的保存地址，可能是本地，可能是网络
        String file = HttpRequestParamter.getString("file");  //文件
        if (StringUtil.isNull(targetWord)) {
            throw new AjaxOperationFailException("目标语音单词不能为空");
        }
        if (StringUtil.isNull(chineseWord)) {
            return new ResponseJson();
        }
        if (StringUtil.isNull(voiceFileUrl)) {
            voiceFileUrl = "";
        }
        if (StringUtil.isNull(file)) {
            file = "";
        }
        Word word = wordMapper.selectByName(targetWord);
        if (word == null) {
            word = new Word();
            word.setTargetword(targetWord);
            word.setPhonetic(phonetic);
            word.setChineseword(chineseWord);
            word.setVoicefileurl(voiceFileUrl);
            word.setFile(file);
            word.setAddip(HttpUtil.getClientIp());
            word.setAddtime(new Date());
            wordMapper.insert(word);
        }
        return new ResponseJson(word.getId(), null);
    }

    /**
     * 看广告记录
     * @return
     * @throws AjaxOperationFailException
     */
    public ResponseJson lookAdvert() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long typeid = HttpRequestParamter.getLong("typeid");
        String mobileModel = HttpRequestParamter.getString("mobileModel"); //机型
        String mobileName = HttpRequestParamter.getString("mobileName"); //手机名称
        if (typeid == 0) {
            throw new AjaxOperationFailException("请选择广告平台");
        }
        if (StringUtil.isNull(mobileModel)) {
            mobileModel = "";
        }
        if (StringUtil.isNull(mobileName)) {
            mobileName = "";
        }
        IntegralType integralType = integralTypeMapper.selectByPrimaryKey(typeid);
        if (integralType == null) {
            throw new AjaxOperationFailException("未找到该广告平台相关信息");
        }

        //修改用户积分信息
        Integral integral = integralMapper.selectByPrimaryKey(uid);
        if (integral == null) {
            integral = new Integral();
            integral.setUid(uid);
            integral.setUseintegral(integralType.getIntegral());
            integral.setTotalintegral(integralType.getIntegral());
            integralMapper.insert(integral);
        } else {
            integral.setUseintegral(integral.getUseintegral() + integralType.getIntegral());
            integral.setTotalintegral(integral.getTotalintegral() + integralType.getIntegral());
            integralMapper.updateByPrimaryKey(integral);
        }
        //添加用户积分记录信息
        IntegralLog integralLog = new IntegralLog();
        integralLog.setUid(uid);
        integralLog.setAddtime(new Date());
        integralLog.setAddip(HttpUtil.getClientIp());
        integralLog.setIntegral(integralType.getIntegral());
        integralLog.setTypeid(typeid);
        integralLog.setMobileModel(mobileModel);
        integralLog.setMobileName(mobileName);
        integralLogMapper.insert(integralLog);
        return new ResponseJson();

    }

    /**
     * 获取查看广告类型
     * @return
     */
    public ResponseJson getIntegralType() {
        return new ResponseJson(null, integralTypeMapper.selectIntegralTypeByType(1));
    }

    /**
     * 查询单词并扣除积分
     * @return
     */
    public ResponseJson getWordInfo() throws AjaxOperationFailException {
        long uid = HttpRequestParamter.getUid();
        long wordid = HttpRequestParamter.getLong("wordid");  //单词id

        if (wordid == 0) {
            throw new AjaxOperationFailException("请选择单词");
        }

        Word word = wordMapper.selectByPrimaryKey(wordid);
        if (word == null) {
            throw new AjaxOperationFailException("该单词不存在");
        }

        //判断改用户是否已查询过该单词
        UserWord userWord = userWordMapper.selectByPrimaryKey(uid, wordid);
        if (userWord != null) {
            return new ResponseJson();
        }

        List<IntegralType> integralTypeList = integralTypeMapper.selectIntegralTypeByType(0);
        long integral = 1;
        if (!StringUtil.isListNull(integralTypeList)) {
            integral = integralTypeList.get(0).getIntegral();
        }
        Integral integralInfo = integralMapper.selectByPrimaryKey(uid);
        if (integralInfo == null || integralInfo.getUseintegral() < integral) {
            return new ResponseJson(115, "积分不足", null, null);
        }
        //修改用户积分信息
        integralInfo.setUseintegral(integralInfo.getUseintegral() - integral);
        integralMapper.updateByPrimaryKey(integralInfo);

        //新增积分记录信息
        IntegralLog integralLog = new IntegralLog();
        integralLog.setUid(uid);
        integralLog.setAddtime(new Date());
        integralLog.setAddip(HttpUtil.getClientIp());
        integralLog.setIntegral(integral);
        integralLog.setTypeid(integralTypeList.get(0).getId());
        integralLog.setMobileModel("");
        integralLog.setMobileName("");
        integralLogMapper.insert(integralLog);

        //新增用户查询单词
        userWord = new UserWord();
        userWord.setUid(uid);
        userWord.setWordid(wordid);
        userWord.setAddtime(new Date());
        userWord.setAddip(HttpUtil.getClientIp());
        userWordMapper.insert(userWord);

        return new ResponseJson();
    }

    /**
     * 获取用户积分记录
     * @return
     */
    public ResponseJson getIntegralLog() {
        long uid = HttpRequestParamter.getUid();
        int page = HttpRequestParamter.getInt("page", 1);
        int count = HttpRequestParamter.getInt("count", 20);
        if (page <= 0) {
            page = 1;
        }
        List<Map<String, Object>> list = integralLogMapper.selectByUid(uid, (page - 1) * count, count);
        return new ResponseJson(null, list);
    }
}
